package com.qfmy.app.controller.novel;

import com.qfmy.app.service.novel.ReadRecordService;
import com.qfmy.app.vo.novel.ReadRecordVo;
import com.qfmy.common.result.Result;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 清风明月
 * @Package com.qfmy.app.controller.novel
 * @date 2025/4/14
 * @description 阅读历史
 */
@RestController
@SuppressWarnings("all")
@RequestMapping("/app/readRecord")
public class ReadRecordController {

   /**
    * 注入service
    */
    @Resource
    private ReadRecordService readRecordService;

    /**
     * 分页获取阅读历史
     */
    @RequestMapping("/getRecentReadBooks")
    public Result<List<ReadRecordVo>> getRecentReadBooks(@RequestParam int pageNum, @RequestParam int size) {
         List<ReadRecordVo> list = readRecordService.getRecentReadBooks(pageNum,size);
        return Result.ok(list);
    }

    /**
     * 根据id删除阅读历史
     */
    @RequestMapping("/deleteReadRecord")
    public Result<String> deleteReadRecord(@RequestParam int id) {
         readRecordService.deleteReadRecord(id);
        return Result.ok("删除成功");
    }

    /**
     * 清除所有的阅读记录
     */
    @RequestMapping("/clearReadRecord")
    public Result<String> clearReadRecord() {
         readRecordService.clearReadRecord();
        return Result.ok("清除成功");
    }

    /**
     * 获取最新的阅读记录
     */
    @RequestMapping("/getNewestReadRecord")
    public Result<ReadRecordVo> getNewestReadRecord() {
        ReadRecordVo newestReadRecord = readRecordService.getNewestReadRecord();
        return Result.ok(newestReadRecord);
    }

    /**
     * 保存阅读记录
     */
    @RequestMapping("/saveReadRecord")
    public Result<String> saveReadRecord(@RequestParam int bookId, @RequestParam int chapterId) {
         readRecordService.saveReadRecord(bookId,chapterId);
        return Result.ok("保存成功");
    }

    /**
     * 根据小说的id获取阅读历史
     */
    @RequestMapping("/getReadRecordByid")
    public Result<ReadRecordVo> getReadRecordByid(@RequestParam int bookId) {
         ReadRecordVo readRecord = readRecordService.getReadRecordByid(bookId);
        return Result.ok(readRecord);
    }


}
